﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DA;
using System.Linq;

namespace qlhocsinh
{
    public partial class Frbaocaotongkethocky : Form
    {

        private baocaotongkethocki_DA _baocaotongkethocki;
        public Frbaocaotongkethocky()
        {
            InitializeComponent();
            _baocaotongkethocki = new baocaotongkethocki_DA();

            combo();
        }
        void combo()
        {
            DataLINQHocSinhDataContext dt = new DataLINQHocSinhDataContext();
            var cb = (from a in dt.BANGDIEMs select new { a.MAHK }).Distinct().ToList();
            cbhocky.DataSource = cb;
            cbhocky.DisplayMember = "MAHK";
            cbhocky.ValueMember = "MAHK";
            
        }
        private void LoadGridView()
        {
            try
            {
                dataGridView1.DataSource = _baocaotongkethocki.LoadDSTongKetHocKy( cbhocky.Text.Length  > 3 ? cbhocky.Text.Substring(cbhocky.Text.IndexOf('=') + 2, 3) : cbhocky.Text);
            }
            catch
            {
                MessageBox.Show("Xảy ra lỗi trong quá trình lấy dữ liệu, hãy kiểm tra lại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Frbaocaotongkethocky_Load(object sender, EventArgs e)
        {
            //string HocKy = cbhocky.Text.ToString().Substring(cbhocky.Text.ToString().Length - 1, 1);
           // dataGridView1.DataSource = _baocaotongkethocki.LoadDSTongKetHocKy(cbhocky.SelectedValue.ToString());
            LoadGridView();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult traloi;
            traloi = MessageBox.Show("Chắc không?", "Trả lời",
                MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (traloi == DialogResult.OK)
                Application.Exit();
        }

        private void cbhocky_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadGridView();
        }
    }
}
